import pygame
from constant import *

SPRITE_BOARD = 32
SPRITE_ROBOT = 28
SPRITE_RESULT = 22
SPRITE_NUMBER_X = 30
SPRITE_NUMBER_Y = 40

#BALL_ROBOT_START_X = 78
#BALL_ROBOT_START_Y = 191
#BALL_ROBOT_DIFF = 14
BALL_ROBOT_START_X = 81
BALL_ROBOT_START_Y = 286
BALL_ROBOT_DIFF = 6

#BALL_BOARD_START_X = 180
#BALL_BOARD_START_Y = 110
#BALL_BOARD_DIFF = 3
BALL_BOARD_START_X = 200
BALL_BOARD_START_Y = 150
BALL_BOARD_DIFF = 3

#RESULT_START_X = 361
#RESULT_START_Y = 116
#RESULT_DIFF = 3
RESULT_START_X = 440
RESULT_START_Y = 156
RESULT_DIFF = 3

NUMBER_START_X = 473
NUMBER_START_Y = 113
NUMBER_DIFF = 0

IMAGE_FILE_BOARD = 'images/board.png'
IMAGE_FILE_ROBOT = 'images/robot.png'
IMAGE_FILE_RESULT = 'images/result.png'
IMAGE_FILE_NUMBER = 'images/number.png'

board = {}
robot = {}
result = {}
number = list()

def init() :
    image_board = pygame.image.load(IMAGE_FILE_BOARD).convert_alpha()
    image_robot = pygame.image.load(IMAGE_FILE_ROBOT).convert_alpha()
    image_result = pygame.image.load(IMAGE_FILE_RESULT).convert_alpha()
    image_number = pygame.image.load(IMAGE_FILE_NUMBER).convert_alpha()
    
    colors = getColors_constants()
    for color in colors :
        x, y = color * SPRITE_BOARD, 0
        board[color] = image_board.subsurface(pygame.Rect(x, y, SPRITE_BOARD, SPRITE_BOARD))
        
    for color in colors :
        x, y = color * SPRITE_ROBOT, 0
        robot[color] = image_robot.subsurface(pygame.Rect(x, y, SPRITE_ROBOT, SPRITE_ROBOT))
            
    results = getResults_constants()
    for r in results :
        x, y = r * SPRITE_RESULT, 0
        result[r] = image_result.subsurface(pygame.Rect(x, y, SPRITE_RESULT, SPRITE_RESULT))
    
    for i in xrange(0, 10) :
        x, y = i * SPRITE_NUMBER_X, 0
        number.append(image_number.subsurface(pygame.Rect(x, y, SPRITE_NUMBER_X, SPRITE_NUMBER_Y)))

def getImageBoard(color) :
    return board[color]

def getImageRobot(color) :
    return robot[color]

def getImageResult(type) :
    return result[type]
    
def getImageNumber(x) :
    return number[x] 